<template>
	<view>
		<!--header-->
		<view class="main-app modal-body">
			<view class="main-content en p-4">
				<form class="form-group login">
                    
					<view>
						<view><label>{{$t('wallet-address')}}</label>
							<view class="mb-3 mt-1">
								<view>
									<view class="recharge_btn" style="padding-left: 20rpx;">{{userinfo.address}}</view>
								</view>
							</view>
						</view>
					</view>

					<view><label class="w-100">
							<view class="d-flex justify-content-between"><label>{{$t('number')}}</label><span
									class="form-label-balance">{{$t('overall_balance')}}: {{account.balance}}USDT</span>
							</view>
						</label>
						<view class="mb-3 mt-1 undefined">
							<u--input :placeholder="input_withdrawal" border="none" v-model="money" color="#fff"
								inputAlign="left" fontSize="14" class="recharge_btn"
								style="background:#556185;padding: 10rpx 24rpx;margin-bottom: 40rpx;"></u--input>


						</view>
					</view>
					<view style="margin-bottom: 10px; line-height: 12px;">
						<span
							style="color: rgb(193, 209, 255); font-size: 10px; opacity: 0.6;">{{$t('Withdrawal_note')}}
						</span><br><span
							style="color: rgb(193, 209, 255); font-size: 10px; opacity: 0.6;">{{$t('mini_withdrawal_amount')}}:
							10 USDT</span><br><span
							style="color: rgb(193, 209, 255); font-size: 10px; opacity: 0.6;">{{$t('pay_taxes')}}:
							6%</span>
							<!-- <br><span
							style="color: rgb(193, 209, 255); font-size: 10px; opacity: 0.6;">{{$t('Single_commission')}}:
							5 USDT -->
						</span>
					</view>
					<view>
						<label>{{$t('Transaction_code')}}</label>
						<view class="mb-3 mt-1 undefined">
							<u--input :placeholder="input_your_password" border="none" v-model="password" color="#fff"
								type="password" inputAlign="left" fontSize="14" class="recharge_btn"
								style="background:#556185;padding: 10rpx 24rpx;margin-bottom: 40rpx;"></u--input>
						</view>
					</view><span style="color: rgb(255, 97, 97); font-size: 10px; opacity: 0.6;"></span>

					<view class="profile-menu-container mt-4" style="width: 100%;">
						<view class="menu-cards row" style="text-align: center; color: #333;">
							
							<u-button type="button" :loading="isLoading" :loadingText="loading"
								@click="withdraw">{{$t('sure')}}</u-button>
						</view>
						<view class="menu-cards row" style="text-align: center; color: #333;margin-top: 20rpx;">
							<u-button type="button" :loading="isLoading" :loadingText="loading" style="background:#c1d1ff;color:#fff"
								@click="goWithdraw">MTCC{{$t('withdraw_money')}}</u-button>
								
						</view>
						
					
					</view>
				</form>
			</view>
		</view>
	</view>

</template>


<script>
	import topWallet from "@/components/nav/top_wallet.vue"
	export default {
		components: {
			topWallet,
		},
		onLoad: function(options) {

		},
		onShow() {
			this.tui.haslogin();
			if (this.tui.isLogin()) {
				this.init();
				this.setTitle()
			}
		},
		data() {
			return {
				isLoading: false,
				loading: this.$t('Load'),
				money: "",
				userinfo: false,
				password: '',
				account: "",
				input_withdrawal: this.$t('input_withdrawal_amount'),
				input_your_password: this.$t('input_your_password')
			}
		},
		methods: {
			recharge() {

			},
			setTitle() {
				uni.setNavigationBarTitle({
					title: this.$t('withdraw_money')
				});
			},
			goWithdraw() {
				uni.navigateTo({
					url: '/pages/my/rutwithdraw'
				})
			},
			init() {

				let token = this.tui.getToken();
				let datas = {
					token: token,
				};
				let account = this.tui.request('/api/user/userAccount', 'post', datas, 1000, 1, '', 'userAccount');
				Promise.resolve(account).then((value) => {
					if (value.code == 200) {
						this.account = value.data;
					} else {
						this.tui.toast(value.message);
					}
				})

				let result = this.tui.request('/api/user/userinfo', 'post', datas, 1000, 1, '', 'userinfo');

				Promise.resolve(result).then((value) => {
					if (value.code == 200) {
						this.userinfo = value.data;

						//写入缓存
					} else {
						this.tui.toast(value.message);
					}
				})

			},

			withdraw() {
				this.isLoading = true;
				if (this.password == '') {
					this.isLoading = false;
					this.tui.toast(this.input_your_password);
					return;
				}
				let token = this.tui.getToken();
				let datas = {
					token: token,
					amount: this.money,
					paypassword: this.password,
					type:2,
				};
				let result = this.tui.request('/api/user/withdraw', 'post', datas, 1000, 1, '', 'withdraw');
				Promise.resolve(result).then((value) => {

					if (value.code == 200) {
						this.tui.toast(value.message);
						setTimeout(() => {
							this.isLoading = false;
							uni.switchTab({
								url: '/pages/my/my'
							})
						}, 1000);
						//写入缓存
					} else {
						this.isLoading = false;
						this.tui.toast(value.message);
					}
				})
			}

		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onPullDownRefresh() {
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 200)
		},


	}
</script>

<style scoped lang="scss">
	.recharge_btn {
		background: rgba(193, 209, 255, .2) !important;
		border-right: none;
		border-bottom: none;
		border-radius: 15px;
		box-shadow: 0 4px 4px 0 rgba(0, 0, 0, .25);
		color: var(--Light-Blue-Solid) !important;
		font-size: 12px;
		height: 48px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>